<?php
/* @var $this ChuongtrinhController */
/* @var $model Chuongtrinh */

$this->breadcrumbs=array(
	'Chương trình'=>array('admin'),
	'Quản lý',
);

$this->menu=array(
	array('label'=>'Quản lý học phần', 'url'=>array('monhoc/admin')),
	array('label'=>'Quản lý danh mục học phần', 'url'=>array('admin')),
	array('label'=>'Quản lý thông tin sinh viên', 'url'=>array('thongtinsv/admin')),
	array('label'=>'Quản lý nhóm lớp', 'url'=>array('nhomlop/admin')),
	array('label'=>'Phát sinh nhóm lớp', 'url'=>array('nhomlop/phatsinh')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$('#chuongtrinh-grid').yiiGridView('update', {
		data: $(this).serialize()
	});
	return false;
});
");
?>

<p><?php	$imgAdd=CHtml::image('addButton.png','Nhập thêm',array()); 
			echo CHtml::link($imgAdd.'&ensp;Thêm mới danh mục học phần',array('create')); ?>&emsp;&emsp;&emsp;&emsp;
<?php echo CHtml::link($imgAdd.'&ensp;Thêm mới danh mục học phầm từ file Excel',array('chuongtrinh/nhapmonhoc')); ?></p>

<h1>Danh mục học phần</h1>

<?php echo CHtml::link('Bộ lọc tìm kiếm','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
	'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php 
$connection=Yii::app()->db;
$commandDV=$connection->createCommand()
	->select('madonvi,tendonvi')
	->from('donvicongtac')
	->query();
$khoa= array();
foreach($commandDV as $rowDV)
{
	//array_push($ngach,$row);
	if(substr( $rowDV['madonvi'],0,1)=='K')
	{
		$khoa[$rowDV['madonvi']]=$rowDV['tendonvi'];
	}
}

$commandKhoilop=$connection->createCommand()
	->select('makhoilop')
	->from('thongtinsv')
	->query();
$KL= array();
foreach($commandKhoilop as $row)
{
	$KL[$row['makhoilop']]=$row['makhoilop'];
}

$command=$connection->createCommand()
			->select('mamh,tenmh')
			->from('monhoc')
			//->where(array('and','username="'.$this->username.'"','level>0'))
			->query();
$hocphan= array();
foreach($command as $row)
{
	//array_push($ngach,$row);
	$hocphan[$row['mamh']]=$row['tenmh'];
}

$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'chuongtrinh-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
/*		array(
			'name'=>'stt',
			'htmlOptions'=>array('width'=>'30'),
		),*/
		array(
			'name'=>'hocki',
			'htmlOptions'=>array('width'=>'30'),
		),
		array(
			'header'=>'Học phần',
			'name'=>'mamh',
			'htmlOptions'=>array('width'=>'150'),
			'value'=>function($model){
				$connection=Yii::app()->db;   // assuming you have configured a "db" connection
			$command=$connection->createCommand()
			->select('mamh,tenmh')
			->from('monhoc')
			//->where(array('and','username="'.$this->username.'"','level>0'))
			->query();
			$hocphan= array();
			foreach($command as $row)
			{
				//array_push($ngach,$row);
				$hocphan[$row['mamh']]=$row['tenmh'];
			}
			foreach($hocphan as $ma=>$ten)
			{
				if($model->mamh==$ma)
				return $ten;
			}},	
			'filter'=>CHtml::dropDownList("Chuongtrinh[mamh]",$model->mamh, $hocphan,array('empty'=>'')),
		),
		array(
			'header'=>'Khoa phụ trách',
			'name'=>'madonvi',
			'value'=>function($model){
				$connection=Yii::app()->db;
				$commandDV=$connection->createCommand()
					->select('madonvi,tendonvi')
					->from('donvicongtac')
					->query();
				$khoa= array();
				foreach($commandDV as $rowDV)
				{
					//array_push($ngach,$row);
					if(substr( $rowDV['madonvi'],0,1)=='K')
					{
					$khoa[$rowDV['madonvi']]=$rowDV['tendonvi'];}
				}
				foreach($khoa as $ma=>$ten)
				{
					if($model->madonvi==$ma)
					return $ten;
				}
			},
			'filter'=>CHtml::dropDownList("Chuongtrinh[madonvi]",$model->madonvi, $khoa,array('empty'=>'')),
		),
		array(
			'header'=>'Khoa dạy',
			'name'=>'madonviday',
			'value'=>function($model){
				$connection=Yii::app()->db;
				$commandDV=$connection->createCommand()
					->select('madonvi,tendonvi')
					->from('donvicongtac')
					->query();
					$khoa= array();
					foreach($commandDV as $rowDV)
					{
						//array_push($ngach,$row);
						if(substr( $rowDV['madonvi'],0,1)=='K')
						{
						$khoa[$rowDV['madonvi']]=$rowDV['tendonvi'];}
					}
			foreach($khoa as $ma=>$ten)
			{
				if($model->madonviday==$ma)
				return $ten;
			}},
			'filter'=>CHtml::dropDownList("Chuongtrinh[madonviday]",$model->madonviday, $khoa,array('empty'=>'')),
		),
		array(
			'header'=> 'Khối lớp',
			'name'=>'nganh',
			'filter'=>CHtml::dropDownList("Chuongtrinh[nganh]",$model->nganh, $KL,array('empty'=>'')),
		),
		/*
		'he',
		'ghichu',
		*/
		array(
			'class'=>'CButtonColumn',
		),
	),
)); ?>